<template>
    <section class="address-edit-main base-main">
      <!--<van-address-edit-->
        <!--:area-list="areaList"-->
        <!--:address-info="addressInfo"-->
        <!--show-set-default-->
        <!--show-search-result-->
        <!--@save="handleSave"-->
        <!--save-button-text="保存并使用"-->
      <!--/>-->
      <!--<ul>-->
        <!--<li v-for="(item,index) in arr[0]">-->
          <!--{{item}}-->
        <!--</li>-->
      <!--</ul>-->

      <van-cell-group>
        <van-field
          v-model="username"
          label="姓名"
          placeholder="收货人姓名"
        />

        <van-field
          v-model="phone"
          type="phone"
          label="电话"
          placeholder="收货人手机号码"
        />

        <van-field
          v-model="add"
          label="地区"
          placeholder="选择省/市/区"
          right-icon="arrow"
          @focus="chooseAdd"
        />

        <van-field
          v-model="detailAdd"
          label="详细地址"
          placeholder="详细地址"
        />

        <van-cell title="设为默认收货地址">
          <template slot="right-icon">
            <van-switch v-model="checked" slot="button" size="24px"/>
          </template>
        </van-cell>
      </van-cell-group>

      <p class="btn-box pdlr15 mt10">
        <span class="base-btn" @click="handleSave">保存并使用</span>
      </p>
    </section>
</template>

<script type="text/ecmascript-6">
import { areaList } from '../../assets/js/area'

  export default {
    data() {
      return {
        username: window.localStorage.getItem('username') ? window.localStorage.getItem('username') : '',
        phone: window.localStorage.getItem('phone') ? window.localStorage.getItem('phone') : '',
        add: window.localStorage.getItem('loc') ? JSON.parse(window.localStorage.getItem('loc')).poiaddress : '',
        detailAdd: window.localStorage.getItem('detailAdd') ? window.localStorage.getItem('detailAdd') : '',
        checked: window.localStorage.getItem('checked') ? Boolean(window.localStorage.getItem('checked')) : false,


//        areaList: areaList,
//        addressInfo: {
//          id: '1',
//          name: '1111',
//          tel: '13562345785',
//          province:'江苏',
//          city:'无锡',
//          county:'崇安区',
//          areaCode:'120000',
//          addressDetail: '1号',
//          isDefault: true,
//        },//收件人信息初始值
//        searchResult: [],
//        show:true,
//        arr:[1,2,3,4,5,6]
      }
    },
    methods: {
      chooseAdd() {

        window.localStorage.setItem('username',this.username)
        window.localStorage.setItem('phone',this.phone)
        window.localStorage.setItem('detailAdd',this.detailAdd)
        window.localStorage.setItem('checked',this.checked)

        this.$router.push({
          name: 'getAddressPage'
        })
      },
      handleSave() {

        let phoneReg = new RegExp("^[1][3,4,5,7,8,9][0-9]{9}$");

        if(!this.username) {
          this.$toast('请填写收货人姓名')
          return false
        } else if(!this.phone) {
          this.$toast('请填写收货人电话')
          return false
        } else if(!phoneReg.test(this.phone)) {
          this.$toast('请正确填写收货人电话')
          return false
        } else if(!this.add) {
          this.$toast('请选择地址')
          return false
        } else if(!this.detailAdd) {
          this.$toast('请填写详细地址')
          return false
        } else {
          console.log(this.username);
          console.log(this.phone);
          console.log(this.add);
          console.log(this.detailAdd);
          console.log(this.checked);
        }
//        console.log('obj--', obj);
//        this.$toast('保存成功');
//        window.localStorage.setItem('addressInfo',obj)
//
//        setTimeout(() => {
//          this.$router.push({
//            path:'/index/web/addressList'
//          })
//        },2000)
      }
    },
  }
</script>

<style lang="scss">
  @import '../../assets/css/addressEditor';

</style>
